<%@include file="/WEB-INF/common/taglibs.jsp"%>
<script type="text/javascript" src="${ctx}/resources/js/datatable-query.js"></script>
<script>
$(document).ready(function(){
	$("form.form-horizontal.seperator[method='post']").validate();
});
	
	
</script>
<div class="row-fluid">

	<div class="span12">

		<div class="page-header">
			<h4>Tax Class </h4>
		</div>

<form class="form-horizontal seperator" method="post">
<!--name --><div class="form-row row-fluid"><div class="span12"><div class="row-fluid"><label class="form-label span3" for="name">Name :</label><input class="span4" id="name" name="name"   type="text" value="${entity.name}" /></div></div></div>
 
 <div class="form-row row-fluid">
				<div class="span12">
					<div class="row-fluid">
						<div class="form-actions">
							<div class="span3"></div>
							<div class="span4 controls">
								<button type="submit" class="btn btn-info marginR10">Save
									changes</button>
								<button class="btn btn-danger">Cancel</button>
							</div>
						</div>
					</div>
				</div>
			</div>
		</form>
<c:if test="${entity.id ne null}">
	<div class="box gradient">
	 
		<div class="title">
				<h4>
				<span>Tax Class Value </span> <span class="box-form right"> </span>
				
				<span class="box-form right taxClassValue_bar"><a href="#" class="btn btn-mini addTaxClassValue">Add Tax Class Value</a></span>
 				</h4>
 				<a href="#" class="minimize"> </a>
			</div>
		 <div class="content scrollable clearfix">
		<table class="table table-bordered table-vertical-centre taxClassValueTable">
			<thead>
				<tr>
					<th><a class="select_all"><span class="icomoon-icon-checkmark-2"></span></a></th>
<th>Name </th>
<th>Tax Rate </th>
<th>Tax Base On </th>
 					<th>Action</th>
				</tr>
			</thead>
		</table>
		</div>
	 
</div>
</c:if>	
	</div>

	<!-- End .span12 -->
	<c:if test="${entity.id ne null}">
 <script>
$(document).ready(function(){
	var del = {
			id : 'taxClassValueDel',
			text  : 'Del',
			domain : "Tax Class Value",
			operation : "Del",
			url : "${ctx}/admin/tax-class-value/del/",
			selector : ".taxClassValue_bar",
			selects  : $('.taxClassValueTable'),
	  
	};
	johnny.tableBtn(del);
	
 	
	
	$('.addTaxClassValue').click(function(){
	$("#taxClassValueDiv").find("div.modal-body").find("input,select,textarea,checkbox").not("[name=action],[type='hidden']").each(function(step,value){
	 									$(value).val("");
	 							});
	
	
	
	 $("#taxClassValueDiv input[name='action']").val("${ctx}/admin/tax-class-value/create/");
 	 $("#taxClassValueDiv").modal('show');
  });
	
	  $(document).delegate('.taxClassValueTable .icomoon-icon-pencil', 'click', function(event) {
		  
		  	var id = $(this).parent().attr("dataid");
			$.ajax({
				url : "${ctx}/admin/tax-class-value/"+id+"/edit/",
				type : "GET",
				dataType : "json",
				success : function(data){		
					if(data && data.state && (data.state.indexOf("ERROR") != -1)){
						johnny.error(data.message);
						return;
					}else{
							var entity = data.entity;
 							$("#taxClassValueDiv").find("div.modal-body").find("input,select,textarea,checkbox").not("[name=action],[type='hidden']").each(function(step,value){
									var name = $(value).attr("name");
    									if (entity[name]){
 										$(value).val(entity[name]);
 										$(value).uniform();
									}else if (name.match(/Id$/)){
										var pro = name.substring(0,name.length-2);
										if (entity[pro] &&entity[pro].id){
											$(value).val(entity[pro].id);
	 										$(value).uniform();
 										}
 										
									}else{
 										$(value).val("");
									}
   									
								
							});
  							
  							$("#taxClassValueDiv input[name='action']").val("${ctx}/admin/tax-class-value/"+id+"/edit/");
     	    				$("#taxClassValueDiv").modal('show');
 					}
				}
			});		  
 
	     
	    });
	var recordColumn = ['','name','taxRate','taxBaseOn' ];
	
	 $('.taxClassValueTable').dataTable({
		"bLengthChange" : true,
		"aoColumnDefs" : [ {
			'bSortable' : false,
			'aTargets' : [0,4 ]
		} ],
 		"sAjaxSource" : '${ctx}/admin/tax-class-value/${entity.id}/',
		"createQueryData" : function (aoData){
				return	johnny.initQueryData(aoData, recordColumn);
		},
		"createResult" : function (json, echo){
 			var dataArray = new Array();
			for ( var i = 0; i < json.result.length; i++) {
				var subArray = new Array();
				var value = johnny.getForSelect(json.result[i].id);
				subArray.push(value);
				subArray.push(json.result[i].name)
subArray.push(json.result[i].taxRate.name)
subArray.push(json.result[i].taxBaseOn)
 
   				var conf = [{
					link : 'javascript:void(1)',
					dataId : json.result[i].id,
					text : 'edit',
					css  : 'icomoon-icon-pencil'
				} 
				
				];
				subArray.push(johnny.getGridLink(conf)); 
  				dataArray.push(subArray);
			}
			return {
				sEcho : echo,
				iTotalRecords : json.totalCount,
				iTotalDisplayRecords : json.totalCount,
				aaData : dataArray
			};
		}		
	});
	 
	
	
	
	
});
 
</script>

 


<div id="taxClassValueDiv" class="modal hide fade"  selector=".taxClassValueTable" style="display: none; ">
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal">
			<span class="icon12 minia-icon-close"></span>
		</button>
		<h3>	Tax Class Value  </h3>
	</div>
 
	<div class="modal-body">
  						<input type="hidden" name="action" >
						<input type="hidden" name="taxClassId" value="${entity.id}" >
<!--name --><div class="form-row row-fluid"><div class="span12"><div class="row-fluid"><label class="form-label span3" for="name">Name :</label><input class="span7" id="name" name="name"   type="text" value="" /></div></div></div>
<!--taxRate --><div class="form-row row-fluid"><div class="span12"><div class="row-fluid"><label class="form-label span3">Tax Rate :</label><div class="span7 controls"><select name="taxRateId"><c:if test="${not empty taxRates}"><c:forEach var="single" items="${taxRates}"><option value="${single.id}" >${single.name}</option></c:forEach></c:if></select></div></div></div></div>
<!--taxBaseOn --><div class="form-row row-fluid"><div class="span12"><div class="row-fluid"><label class="form-label span3">Tax Base On :</label><div class="span7 controls"><select name="taxBaseOn"><c:if test="${not empty taxBaseOns}"><c:forEach var="single" items="${taxBaseOns}"><option value="${single}">${single}</option></c:forEach></c:if></select></div></div></div></div>
 
						 
	</div>
	 
	<div class="modal-footer">
		<a href="#" class="btn" data-dismiss="modal">Close</a>
		<a href="#" class="btn btn-primary modal-submit">Save changes</a>
	</div>

</div>
</c:if>	


</div>
<!-- End .row-fluid --> 

